<?php
$error = "";
if($_POST['act'] && $_POST['act']=='change_tree'){
    if($_POST['member_id']!="" && $_POST['d_member_id']>0){
        include_once("../module/micro_shop/includes/plugin_micro_shop_class.php");
        $microShop = new MicroShop();
        //更改关系
        $status = $microShop->bindMemberToOtherTree($_POST['member_id'], $_POST['d_member_id'],$error);
        //发红包
        if($status){
            if($_POST['give_bonus']==1){
                $bStatus = $microShop->giveOutBonusOfRecShop($_POST['member_id']);
                if(!$bStatus){
                    die(json_encode(array('code'=>'-2','msg'=>'关系更改成功，发红包不成功')));
                }
            }
        }
        if(empty($error)){
            die(json_encode(array('code'=>'0','msg'=>'成功！')));
        }else{
            die(json_encode(array('code'=>'-1','msg'=>$error)));
        }
    }else{
        die(json_encode(array('code'=>'-1','msg'=>'未填写用户ID或未填写要绑定到谁的用户ID！')));
    }
}

$tpl->display('change_tree.htm');